def pr(n):
  p = 1
  if n<2:
    p = 0
  else:
    for i in range(2, n//2+1):
      if n % i == 0:
        p = 0
  return p

a = input()
b = 0
c = []

if 1000<=int(a)<=9999:
  c.append(int(a))
  c.append(int(a[0]))
  c.append(int(a[1]))
  c.append(int(a[2]))
  c.append(int(a[3]))
  c.append(int(a[0:2]))
  c.append(int(a[0:3]))
  c.append(int(a[1:3]))
  c.append(int(a[1:]))
  c.append(int(a[2:]))

  for i in range(10):
    if pr(c[i]) == 1 and c[i] > b:
      b = c[i]
  print(b)
  

else:
  print(0)



    



